package org.gavin.core.validator;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.apache.commons.lang3.StringUtils;
import org.gavin.core.annotation.SpecialCharacters;
import org.gavin.core.utils.ValidatorUtils;

/**
 * SpecialCharactersValidator
 * 特殊字符验证
 *
 * @author grl
 * @date 2022/5/5
 */
public class SpecialCharactersValidator implements ConstraintValidator<SpecialCharacters,String> {
    @Override
    public void initialize(SpecialCharacters constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    @Override
    public boolean isValid(String str, ConstraintValidatorContext constraintValidatorContext) {
        if(StringUtils.isBlank(str)){
            return true;
        }
        return !ValidatorUtils.containSpecial(str);
    }
}
